<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <router-link to="/product">商品管理</router-link>
<!--    显示路由的组件-->
    <router-view></router-view>
</div>
<template id="product">
    <div>
        <h1>商品管理</h1>
<!--        嵌套路由-->
        <router-link to="/product/add">新增商品</router-link>
        <router-link to="/product/edit">编辑商品</router-link>
<!--        router-view用来显示子组件-->
        <router-view></router-view>
    </div>
</template>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!--引入js-->
<script src="https://unpkg.com/vue-router@3.6.5/dist/vue-router.js"></script>

<script>
    //声明组件模板
    const product={
        template:"#product"
    };
    const add={
        template: "<h3>商品添加</h3>"
    };
    const edit={
        template: "<h3>商品编辑</h3>"
    };
    //创建路由对象
    const router=new VueRouter({
        routes:[
            //绑定路径和路由对象
            {
                path:"/product",
                component:product,
                // 绑定子路由
                children:[
                    {path:"add",component: add},
                    {path:"edit",component: edit}
                ]
            }
        ]
    });

    const app = new Vue({
        el: "#app",
        data: {},
        methods: {},
        components: {},
        router:router //绑定路由对象
    })
</script>
</body>
</html>